package com.suypower.carManage.action;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Vector;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONArray;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.jarp.db.DAO;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.suypower.carManage.VO.MetaDataVO;
import com.suypower.carManage.comm.ConstUtil;

public class GetMetadata extends ActionSupport implements ServletRequestAware{

	private String code;
	private String _dc;
	private String query;
	
	
	
	public String getQuery() {
		return query;
	}


	public void setQuery(String query) {
		this.query = query;
	}


	public String get_dc() {
		return _dc;
	}


	public void set_dc(String dc) {
		_dc = dc;
	}


	public String getCode() {
		return code;
	}


	public void setCode(String code) {
		this.code = code;
	}


	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public String execute(){
		
		DAO dao=new DAO();
		String sql="SELECT * FROM tb_metadata t WHERE t.code='"+code+"'";
		ArrayList<MetaDataVO> list=new ArrayList<MetaDataVO>();
		try {
			Vector v=dao.getDataSet(ConstUtil.DBNAME, sql);
			if(v!=null){
				for(int i=0;i<v.size();i++){
					Hashtable hash=(Hashtable)v.get(i);
					MetaDataVO meta=new MetaDataVO();
					meta.setCode((String)hash.get("CODE"));
					meta.setName((String)hash.get("NAME"));
					meta.setId((String)hash.get("ID"));
					meta.setValue((String)hash.get("VALUE"));
					list.add(meta);
				}
				
				JSONArray json=JSONArray.fromObject(list);
				ActionContext.getContext().put("json", json.toString());
			}else{
				
			}
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return this.SUCCESS;
	}
}
